/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package view;

import control.GuiManager;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import javax.swing.JMenuItem;

/**
 *
 * @author Jojo
 */
public class ObjectCardSensor extends ObjectCard{
    String sensorPort = "1";
    
    ObjectCardSensor(String pName, int pSensorTyp){
        super(pName, pSensorTyp);
        this.setPreferredSize(new Dimension(180,50));
        this.setSize(new Dimension(180,50));
        this.setMaximumSize(new Dimension(180,50));
        this.setMinimumSize(new Dimension(180,50));
        this.addContextMenu();
    }
    
    @Override
    protected void paintComponent(Graphics g) {
        super.paintComponent(g);
        Graphics2D g2d = (Graphics2D) g.create();
        Dimension d = this.getSize();
        g2d.drawLine(0,20,d.width-2,20);
        g2d.drawString("sensorPort = "+sensorPort,  10,35);
    }
    
    void addContextMenu(){
        
                
                JMenuItem jmiChangeSensorPort = new JMenuItem();
        jmiChangeSensorPort.setText("ändere Sensorport");

        
        
        jmiChangeSensorPort.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                sensorPort = getUserChange("Sensorport festlegen (Zahl von 1 bis 4)");
                repaint();
                validate();
            }
        });
        
        this.jPopupMenu1.add(jmiChangeSensorPort);
    }
    
    void cardClicked(){
            String outputText = "";
            switch (this.cardId) {
            case 3:  outputText = "Lichtsensor "+ objectName+" = new Lichtsensor("+this.sensorPort+");"+"\n";
                     break; 
            case 4:  outputText = "Farbsensor "+ objectName+" = new Farbsensor("+this.sensorPort+");"+"\n";
                     break; 
            case 5:  outputText = "Ultraschallsensor "+ objectName+" = new Ultraschallsensor("+this.sensorPort+");"+"\n";
                     break; 
            case 6:  outputText = "Soundsensor "+ objectName+" = new Soundsensor("+this.sensorPort+");"+"\n";
                     break; 
            case 7:  outputText = "Touchsensor "+ objectName+" = new Touchsensor("+this.sensorPort+");"+"\n";
                     break;  
            default: outputText = "Fehler";
                     break;
        }
            GuiManager.getActivePane().insert(outputText, GuiManager.getActivePane().getCaretPosition());
    }
    
}
